package com.goktech.olala.client.controller.index;

import com.goktech.olala.client.controller.basic.BasicController;
import com.goktech.olala.core.resp.RespBrandVo;
import com.goktech.olala.core.resp.RespCategoryVo;
import com.goktech.olala.core.service.IActivitService;
import com.goktech.olala.core.service.IAdversService;
import com.goktech.olala.core.service.IArticleService;
import com.goktech.olala.core.service.IGoodCategory;
import com.goktech.olala.server.pojo.goods.Activit;
import com.goktech.olala.server.pojo.goods.Advers;
import com.goktech.olala.server.pojo.goods.Article;
import com.goktech.olala.server.pojo.goods.Brand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @Classname IndexController
 * @Description TODO
 * @Date 2020/11/29 16:54
 * @Created by ASUS
 */
@Controller
@RequestMapping("/index")
public class IndexController extends BasicController {

    @Autowired
    IArticleService articleService;
    @Autowired
    IAdversService adversService;
    @Autowired
    IActivitService activitService;
    @Autowired
    IGoodCategory goodCategory;
    
    
    ModelAndView mav = new ModelAndView();

//    @RequestMapping("/")
//    public ModelAndView index(){
//        mav.setViewName("redirect:index/init.do");
//        return mav;
//    }

    @RequestMapping("/init.do")
    public ModelAndView toIndex(){
//        mav.setViewName("redirect:home/index");

        //商城头条
        List<Article> articles = articleService.selectAll();
        mav.addObject("articleVoList",articles);
        //轮播图
        List<Advers> advers = adversService.selectAll();
        mav.addObject("ctmAdvers",advers);
        //热门活动
        List<Activit> activits = activitService.selectAll();
        mav.addObject("indexActivities",activits);
        //一级目录
        List<RespCategoryVo> respCategoryVos = goodCategory.selectByCategory();

        for (RespCategoryVo first: respCategoryVos) {
            List<RespBrandVo> brands = goodCategory.selectBrand();
            if (brands!=null){
                first.setBrandList(brands);
            }
        }

        mav.addObject("categoryList",respCategoryVos);

        mav.setViewName("home/index");
        return mav;
    }

}
